﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace TeacherHelp.FormList.Teacher
{
    public partial class ExercisesRemoveForm : BanFlashingForm
    {
        private readonly TeacherMainForm _parentForm;
        private readonly string _exercisesId;

        private ExercisesRemoveForm()
        {
            InitializeComponent();
        }

        public ExercisesRemoveForm(TeacherMainForm parent, string exercisesId) : this()
        {
            _parentForm = parent;
            _exercisesId = exercisesId;
        }

        private void ExercisesRemoveForm_Load(object sender, EventArgs e)
        {
            //题目难度
            List<dynamic> difficultylist = new List<dynamic>{
                new { Id = 1, Value = "简单" },
                new { Id = 2, Value = "中等" },
                new { Id = 3, Value = "困难" }
            };
            this.ExercisesDifficultyComBox.DataSource = difficultylist;
            this.ExercisesDifficultyComBox.DisplayMember = "Value";
            this.ExercisesDifficultyComBox.ValueMember = "Id";

            //科目类型
            BLL.SubjectsManager subjectsManager = new BLL.SubjectsManager();
            this.SubjectsTypeComBox.DataSource = subjectsManager.GetSubejctAll();
            this.SubjectsTypeComBox.DisplayMember = nameof(Model.Subjects.Name);
            this.SubjectsTypeComBox.ValueMember = nameof(Model.Subjects.Id);

            //初始化值
            BLL.ExercisesManager exercisesManager = new BLL.ExercisesManager();
            ViewModel.Exercises exercises = exercisesManager.GetExerciseModel(_exercisesId);
            ExercisesAnswerTxt.Text = exercises.Answer;
            OptionATxt.Text = exercises.Aoption;
            OptionBTxt.Text = exercises.Boption;
            OptionCTxt.Text = exercises.Coption;
            OptionDTxt.Text = exercises.Doption;
            ExercisesTxt.Text = exercises.Content;
            ExercisesDifficultyComBox.Text = exercises.Difficulty;
            SubjectsTypeComBox.Text = exercises.SubjectName;
        }

        private void RemoveBtn_Click(object sender, EventArgs e)
        {
            ExercisesRemove();
        }

        public void ExercisesRemove()
        {
            if (MessageBox.Show("确定要删除吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
            {
                return;
            }
            BLL.ExercisesManager exercisesManager = new BLL.ExercisesManager();
            string result = exercisesManager.ExercisesRemove(_exercisesId.ToInt());
            MessageBox.Show(result ?? "删除成功！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Information);
            _parentForm.ChildFormInt();
        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            _parentForm.ChildFormInt();
        }
    }
}
